package com.sss.day35_mvc_mybatis.util;

/**
 * |-----------------------------------------------
 * |  ____   _          _____  _      _  _        |
 * | / __ \ (_)        / ____|| |    (_)(_)       |
 * || |  | | _  _   _ | (___  | |__   _  _  _   _ |
 * || |  | || || | | | \___ \ | '_ \ | || || | | ||
 * || |__| || || |_| | ____) || | | || || || |_| ||
 * | \___\_\|_| \__,_||_____/ |_| |_||_|| | \__,_||
 * |                                   _/ |       |
 * |                                  |__/        |
 * |-----------------------------------------------
 * |                 天道酬勤                     |
 * |             代码敲烂 月薪过万                |
 * L----------------------------------------------
 *
 * @desc 该类用于前后交互时,统一json格式
 */
public class R {

    private int code;
    private String msg;
    private Object data;

    /**
     * 创建几个工具方法
     * @return
     */
    public static R ok(){
        R r = new R( );
        r.setCode(2000);
        r.setMsg("成功");
        return r;
    }
    public static R ok(int code,String msg){
        R r = new R( );
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
    public static R ok(Object data){
        R r = new R( );
        r.setCode(2000);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }
    public static R ok(int code,String msg,Object data){
        R r = new R( );
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R fail(){
        R r = new R( );
        r.setCode(1000);
        r.setMsg("失败");
        return r;
    }
    public static R fail(String msg){
        R r = new R( );
        r.setCode(1000);
        r.setMsg(msg);
        return r;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
